package simplifiedPastry.simpleTester;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;

import simplifiedPastry.Message;
import simplifiedPastry.MessageListener;
import simplifiedPastry.NodeId;

class MessagePrinter implements MessageListener {

	@Override
	public void ioError(IOException exception) {
		System.out.println("-----------ioError----------------\n"
				+ exception.getMessage()
				+ "\n----------------------------------");
		exception.printStackTrace();
	}

	@Override
	public void kSearchRecv(NodeId[] nodeArray) {
		System.out.println("------------kSearchRecv-----------\n"
				+ Arrays.toString(nodeArray)
				+ "\n----------------------------------");
	}

	@Override
	public void kSearchTimeout(NodeId serachId) {
		System.out.println("----------kSearchTimeout----------\n"
				+ serachId + "\n----------------------------------");
	}

	@Override
	public void messageAccepted(Message message) {
		System.out.println("----------messageAccepted---------\n"
				+ "'" + new String(message.getByte()) + "'\n"
				+ "----------------------------------");
	}

	@Override
	public void messageRecv(Message message, NodeId senderId) {
		System.out.println("------------messageRecv-----------\n"
				+ "from " + senderId + " '"
				+ new String(message.getByte()) + "'\n" + 
				"----------------------------------");
	}

	@Override
	public void messageTimeout(Message message) {
		System.out.println("------------messageTimeout--------\n"
				+ message + "\n----------------------------------");
	}

	@Override
	public void nodeNotFound(NodeId recvId) {
		System.out.println("------------nodeNotFound----------\n"
				+ recvId + "\n----------------------------------");
	}
	
}
